package com.hnhs.controller;

import com.hnhs.info.CateproInfo;
import com.hnhs.mapper.CateProMapper;
import com.hnhs.service.CategoryProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/")
public class CateproController {
    @Autowired
    private CategoryProductService service;
    @Autowired
    private CateProMapper cateProMapper;

    @GetMapping("cateCount")
    public int categoryCount(){
        return service.categoryCount();
    }
    @GetMapping("todayCount")
    public int categoryTodayCount(){
        return service.categoryCount();
    }

    @GetMapping("proCount")
    public int ProductCount(){
        return service.productCount();
    }

    @GetMapping("protodayCount")
    public int ProductTodayCount(){
        return service.productTodayCount();
    }

    @GetMapping("pieCount")
    public List<Map<String,Object>> selectByCount(){
        List<CateproInfo> cateproInfos = cateProMapper.selectByCount();
        System.out.println(cateproInfos);
        List<Map<String,Object>> mapList =new ArrayList<>();
        for (CateproInfo cateproInfo : cateproInfos) {
            if(cateproInfo.getProduct_count() == 0){
                continue;
            }
            Map<String,Object> map=new HashMap<>();
            map.put("name",cateproInfo.getCategory_name());
            map.put("value",cateproInfo.getProduct_count());
            mapList.add(map);
        }
        return mapList;
    }

}
